home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / General tools / Audit app & dcmd / Src / WindowUtilities.c < prev   
Encoding:
C/C++ Source or Header  |  1993-09-17  |  4.3 KB  |  160 lines  |  [TEXT/KAHL]

  1. /*                                WindowUtilities.c                                */
  2. /*
  3.  * WindowUtilities.c
  4.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  5.  * These functions are called when the window is zoomed or resized.
  6.  */
  7. #include "DisplayAudit.h"
  8.  
  9. #ifndef topLeft
  10. #define topLeft(r)    (((Point *) &(r))[0])
  11. #define botRight(r)    (((Point *) &(r))[1])
  12. #endif
  13.  
  14. /*
  15.  * DoZoomWindow
  16.  * Algorithm from New Inside Mac (Toolbox Essentials) 4-55
  17.  */
  18. void
  19. DoZoomWindow(
  20.         WindowPtr                        theWindow,
  21.         short                            whichPart
  22.     )
  23. {
  24.         GDHandle                gd;
  25.         GDHandle                gdZoom;
  26.         GrafPtr                    savePort;
  27.         Rect                    windowRect;
  28.         Rect                    zoomRect;
  29.         Rect                    intersection;
  30.         long                    thisArea;
  31.         long                    greatestArea;
  32.         short                    windowTitleHeight;
  33. #define PEEK    (*((WindowPeek) theWindow))
  34. #define STATE    (**((WStateDataHandle) PEEK.dataHandle))
  35.  
  36.         GetPort(&savePort);
  37.         SetPort(theWindow);
  38.         if (whichPart == inZoomOut) {
  39.             if (gHasColorQuickDraw == FALSE) {
  40.                 /*
  41.                  * This shouldn't happen on an AOCE system, but,
  42.                  * if it does, just force a single screen zoom.
  43.                  */
  44.                 zoomRect = qd.screenBits.bounds;
  45.                 InsetRect(&zoomRect, 4, 4);
  46.                 STATE.stdState = zoomRect;
  47.             }
  48.             else {
  49.                 /*
  50.                  * We have color QuickDraw. Locate the screen that contains
  51.                  * the largest area of the window and zoom to that screen.
  52.                  */
  53.                 windowRect = theWindow->portRect;
  54.                 LocalToGlobal(&topLeft(windowRect));
  55.                 LocalToGlobal(&botRight(windowRect));
  56.                 windowTitleHeight = windowRect.top
  57.                         - 1
  58.                         - (**PEEK.strucRgn).rgnBBox.top;
  59.                 windowRect.top -= windowTitleHeight;
  60.                 greatestArea = 0;
  61.                 gdZoom = NULL;
  62.                 /*
  63.                  * Look at all graphics devices and find an intersection. Then
  64.                  * select the largest intersecting screen.
  65.                  */
  66.                 for (gd = GetDeviceList(); gd != NULL; gd = GetNextDevice(gd)) {
  67.                     if (TestDeviceAttribute(gd, screenDevice)
  68.                      && TestDeviceAttribute(gd, screenActive)
  69.                      && SectRect(&windowRect, &(**gd).gdRect, &intersection)) {
  70.                         thisArea = ((long) width(intersection))
  71.                                  * ((long) height(intersection));
  72.                         if (thisArea > greatestArea) {
  73.                             greatestArea = thisArea;
  74.                             gdZoom = gd;
  75.                         }
  76.                     }
  77.                 }
  78.                 /*
  79.                  * If we're zooming to the device with the menu bar,
  80.                  * allow for its height.
  81.                  */
  82.                 if (GetMainDevice() == gdZoom)
  83.                     windowTitleHeight += GetMBarHeight();
  84.                 zoomRect = (**gdZoom).gdRect;
  85.                 InsetRect(&zoomRect, 3, 3);
  86.                 zoomRect.top += windowTitleHeight;
  87.                 STATE.stdState = zoomRect;
  88.             }                                        /* End if color QuickDraw    */
  89.         }                                            /* End if zoom out            */
  90.         ZoomWindow(theWindow, whichPart, (theWindow == FrontWindow()));
  91.         /*
  92.          * Zoom redraws the entire window.
  93.          */
  94.         EraseRect(&theWindow->portRect);
  95.         InvalRect(&theWindow->portRect);
  96.         SetPort(savePort);            
  97. #undef PEEK
  98. #undef STATE
  99. }
  100.  
  101. /*
  102.  * DoGrowWindow
  103.  * Algorithm from New Inside Mac (Toolbox Essentials) 4-58
  104.  * We assume that the window can cover the entire screen.
  105.  */
  106. Boolean
  107. DoGrowWindow(
  108.         WindowPtr                        theWindow,
  109.         short                            minimumWidth,
  110.         short                            minimumHeight
  111.     )
  112. {
  113.         long                    growSize;
  114.         Rect                    limitRect;
  115.         Rect                    viewRect;
  116.         RgnHandle                localUpdateRgn;
  117.         
  118.         limitRect.left = minimumWidth;
  119.         limitRect.top = minimumHeight;
  120.         limitRect.right = qd.screenBits.bounds.right;
  121.         limitRect.bottom = qd.screenBits.bounds.bottom;
  122.         growSize = GrowWindow(theWindow, EVENT.where, &limitRect);
  123.         if (growSize != 0) {
  124. #if 0    /* This doesn't quite work right    */
  125.             /*
  126.              * Window size changed. Get our update region in
  127.              * local coordinates.
  128.              *
  129.              * viewRect is our "real" content area.
  130.              */
  131.             viewRect = theWindow->portRect;
  132.             localUpdateRgn = NewRgn();
  133.             CopyRgn(((WindowPeek) theWindow)->updateRgn, localUpdateRgn);
  134.             OffsetRgn(
  135.                 localUpdateRgn,
  136.                 theWindow->portBits.bounds.left,
  137.                 theWindow->portBits.bounds.top
  138.             );
  139. #else
  140. #pragma unused (viewRect, localUpdateRgn)
  141. #endif
  142.             SizeWindow(theWindow, LoWord(growSize), HiWord(growSize), TRUE);
  143.             /*
  144.              * Force a redraw of the entire window, but exclude the
  145.              * intersection of the old view rect and the new view rect.
  146.              * Invalidate any prior update region in any case.
  147.              */
  148.             EraseRect(&theWindow->portRect);
  149.             InvalRect(&theWindow->portRect);
  150. #if 0
  151.             (void) SectRect(&viewRect, &theWindow->portRect, &viewRect);
  152.             ValidRect(&viewRect);
  153.             InvalRgn(localUpdateRgn);
  154.             DisposeRgn(localUpdateRgn);
  155. #endif
  156.         }
  157.         return (growSize != 0);
  158. }
  159.  
  160.